﻿
pages_paymentIn_ItemIn = new function () {   
    this.m_objPageItem = new Paging("divItemPaging", "pages_paymentIn_ItemIn.bindData", "pagingCss", 10, 5);

    this.documentReady = function () {
        this.bindData(1, this.m_objPageItem.pageSize);
    };

    this.bindData = function (_cur, _ps) {
        Loading.showProcess();
        $.ajax({
            type: "GET",
            url: "/handler/ItemInHandler.ashx",
            data: {currentPage: _cur, pageSize: _ps, t: "GetListItemIn" },
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
                pages_paymentIn_ItemIn.processData(data, _cur);
                Loading.closeProcess();
            }
        });

    };

    this.processData = function (data, _cur) {        
        $("#divItem").setTemplateURL("/templates/paymentIn/itemin.htm");
        $("#divItem").processTemplate(data);
        pages_paymentIn_ItemIn.setStyleRow("#divItem");
        pages_paymentIn_ItemIn.m_objPageItem.bindPaging(_cur, data.TotalRecord);
        if (data.TotalRecord <= pages_paymentIn_ItemIn.m_objPageItem.pageSize) {
            $("#divItemPaging").attr('style', 'display:none');
        }
        else {
            $("#divItemPaging").attr('style', 'display:block');
        }
    };
    
    $("#aBuyItem").live('click', function () {
        Loading.showProcess();
        var id = $(this.parentNode).attr("id").substring(3);
        var _data = {
            id: id
        };
        $.ajax({
            type: "POST",
            url: "/WebService/WSItemIn.asmx/BuyItem",
            data: JSON.encode(_data),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
                Loading.closeProcess();
                if (data == 1) {
                    alert("bạn chưa đăng nhập");
                    return;
                }                
            }
        });

    });

}